package com.beans;

import java.io.Serializable;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.http.HttpSession;

import model.Cinema;
import model.Seat;

import com.Constants;
import com.factory.Util;
import com.services.SeatsService;

public class SeatsBean implements Serializable {

	@EJB
	SeatsService service;

	private List<Seat> seats;

	public SeatsBean() {

	}

	public List<Seat> getSeats() {
		HttpSession session = Util.getSession();
		int userId = ((Integer) (session.getAttribute(Constants.USER_ID)))
				.intValue();

		this.seats = service.getAllMovies(userId);
		return seats;
	}

	public void setSeats(List<Seat> seats) {
		this.seats = seats;
	}

	public String getAllSeatsForProjectionString(Seat seat) {
		List<Integer> seatNumbers = service.getAllSeatsForProjection(seat);

		StringBuilder builder = new StringBuilder();
		builder.append(seatNumbers.remove(0));

		for (Integer s : seatNumbers) {
			builder.append(", ");
			builder.append(s);
		}

		return builder.toString();
	}

	public String getAllSeatsForProjectionPrice(Seat seat) {
		return service.getAllSeatsForProjectionPrice(seat);
	}

}
